package zzzhc.image.model;

import java.util.HashMap;
import java.util.Map;

import zzzhc.image.recognize.nn.NNOutput;
import zzzhc.image.recognize.nn.NNOutputItem;

public class NNTableModel extends NormalTableModel {

	private static final long serialVersionUID = 4892415969058222004L;

	private static final String[] COLUMNS = { "对应字符", "网络输出" };

	public NNTableModel() {
		init(COLUMNS, new Class[] { String.class, String.class },
				new Boolean[] { true, true });
	}

	public void addColumns(NNOutput output) {
		if (output.getItems().size() == 0) {
			return;
		}
		removeAllColumns();
		double[] data = output.getItems().get(0).getData();
		addColumnInfo(COLUMNS[0], String.class, true);
		for (int i = 0; i < data.length; i++) {
			addColumnInfo(String.valueOf(i), String.class, true);
		}

		for (NNOutputItem item : output.getItems()) {
			addColumn(item);
		}
	}

	public void addColumn(NNOutputItem item) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(COLUMNS[0], item.getCode());
		for (int i = 0; i < item.getData().length; i++) {
			map.put(String.valueOf(i), item.getData()[i]);
		}
		addRow(map);
	}
}
